use crate::window_state::WindowState;
use imgui::Ui;
use std::sync::{Arc, Mutex};

pub struct GuiManager {
    window_state: Arc<Mutex<WindowState>>,
}

impl GuiManager {
    pub fn new(window_state: Arc<Mutex<WindowState>>) -> Self {
        Self { window_state }
    }

    pub fn run(&self) {
        let window_state = self.window_state.clone();
        crate::support::simple_init(file!(), move |run, ui| {
            let mut state = window_state.lock().unwrap();
            if state.show {
                GuiManager::render_main_window(ui, &mut state); 
            }
        });
    }

    fn render_main_window(ui: &Ui, state: &mut WindowState) {
        ui.window("主窗口")
            .size([300.0, 200.0], imgui::Condition::FirstUseEver)
            .build(|| {
                ui.text("这是主应用窗口");
                if ui.button("关闭") {
                    state.show = false;
                }
            });
    }
}